package com.jie.controller;


import com.jie.entity.Role;
import com.jie.service.RoleService;
import com.jie.util.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwq
 * @since 2022-01-04
 */
@RestController
@RequestMapping("/role")
@Api(tags = "角色")
public class RoleController {
    @Autowired
    private RoleService roleService;
//    @OptLog(optType = SELECT)
    @ApiOperation(value = "获取全部角色")
    @GetMapping("/roles/list")
    public List<Role> getAllRoles(){
        return roleService.list();
    }

    @ApiOperation(value = "根据id删除角色信息")
    @PostMapping("/roles/list/{id}")
    public RespBean delectRole(@PathVariable("id") int id){
        boolean flag=roleService.delectById(id);
        return flag?RespBean.success("删除成功"):RespBean.error("删除失败");
    }

    @ApiOperation(value = "更新角色信息")
    @PostMapping("/updateRole")
    public RespBean updateRole(@RequestBody Role role){
        boolean flag=roleService.updateById(role);
        return flag?RespBean.success("更新成功"):RespBean.error("更新失败");
    }

}

